#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QStatusBar* statusBar = this->statusBar();
    this->setStatusBar(statusBar);

    // 显示实时消息，第二个参数是显示时间，单位ms，置为0表示持久化显示
//    statusBar->showMessage("Hello World", 3000);

    QLabel* label = new QLabel("这是一条状态栏信息");
    statusBar->addWidget(label);

    QLabel* label2 = new QLabel("靠右显示的状态栏信息");
    statusBar->addPermanentWidget(label2);

    pb = new QProgressBar;
    pb->setRange(0, 100);
    pb->setValue(0);
    statusBar->addWidget(pb);

    time = new QTimer;
    connect(time, &QTimer::timeout, this, &MainWindow::handle);
    time->start(100);
}

void MainWindow::handle()
{
    int val = pb->value();
    if(val >= 100)
    {
        time->stop();
        return;
    }

    pb->setValue(val + 1);
}

MainWindow::~MainWindow()
{
    delete ui;
}

